package com.zzyl.controller;

import com.zzyl.event.UserRegisterEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class UserRegisterController {

    @Autowired
    private ApplicationContext context;

    @GetMapping("/register")
    public String register(@RequestParam("name")String name){
        log.info(name + "用户注册成功");
        // 发布用户注册成功的事件
        context.publishEvent(new UserRegisterEvent(this, name));
        return "success";
    }
}
